﻿package mortal.game.view.copy.groupCopy.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.mvc.core.*;

    public class GroupCopyInfoPanel extends GroupCopyBasePanel
    {
        private var _pageSelecter:PageSelecter;
        private var _bigMap:GImageBitmap;
        private var _copyTitle:GImageBitmap;
        private var _rewardList:GTileList;
        private var _copyList:GTileList;
        private var _copyName:GroupCopyName;
        private var _isHidCarrar:Boolean;
        private var _tcopy:TCopy;
        private var _currentPanel:GroupCopyBaseListPanel;
        private var _limitNum:BitmapNumberText;
        private var _totalNum:BitmapNumberText;
        private var _dicIndexClass:Dictionary;

        public function GroupCopyInfoPanel()
        {
            this._dicIndexClass = new Dictionary();
            return;
        }// end function

        private function initPanelClass() : void
        {
            this._dicIndexClass[0] = GroupCopyListPanel;
            this._dicIndexClass[1] = GroupCopyMateInfoPanel;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            this.initPanelClass();
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(7, 5, 415, 542, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyRewardBg, 18, 458, this));
            this.pushUIToDisposeVec(UIFactory.bg(425, 5, 467, 245, this));
            this.pushUIToDisposeVec(UIFactory.bg(425, 253, 467, 294, this));
            this.pushUIToDisposeVec(UIFactory.bg(423, 254, 467, 25, this, ImagesConst.RegionTitleBg));
            var _loc_1:* = GlobalStyle.textFormatBai.center();
            this._pageSelecter = UIFactory.pageSelecter(790, 212, this, PageSelecter.SingleMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, _loc_1);
            this._pageSelecter.currentPage = 1;
            this._pageSelecter.pageTextBoxSize = 50;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._bigMap = UIFactory.gImageBitmap("", 10, 7, this);
            this._copyTitle = UIFactory.gImageBitmap("", 156, 12, this);
            this._rewardList = UIFactory.tileList(26, 484, 500, 50, this);
            this._rewardList.columnWidth = 48;
            this._rewardList.rowHeight = 48;
            this._rewardList.horizontalGap = 0;
            this._rewardList.verticalGap = 0;
            this._rewardList.setStyle("cellRenderer", GroupCopyRewardCellRender);
            this._copyList = UIFactory.tileList(425, 6, 480, 450, this);
            this._copyList.columnWidth = 237;
            this._copyList.rowHeight = 103;
            this._copyList.horizontalGap = -5;
            this._copyList.verticalGap = -6;
            this._copyList.setStyle("cellRenderer", GroupCopyListRender);
            this._copyList.configEventListener(Event.CHANGE, this.handleCellRendererChange);
            this._copyList.selectedIndex = -1;
            this._copyName = UICompomentPool.getUICompoment(GroupCopyName);
            this._copyName.x = 215;
            this._copyName.y = 440;
            this.addChild(this._copyName);
            this._limitNum = UIFactory.bitmapNumberText(595, 205, "GroupCopyNum.png", 31, 35, -16, this, 13, BitmapNumberText.Mid);
            this._limitNum.text = "22";
            this._totalNum = UIFactory.bitmapNumberText(647, 205, "GroupCopyNum.png", 31, 35, -16, this, 13, BitmapNumberText.Mid);
            this._totalNum.text = "10";
            this.updateCopyList();
            this.updateLimitNum();
            LoaderHelp.addResCallBack(ResFileConst.groupCopy, this.showSkin);
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupEnterNum));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._pageSelecter.dispose(param1);
            this._pageSelecter = null;
            this._rewardList.dispose(param1);
            this._rewardList = null;
            this._copyList.dispose(param1);
            this._copyList = null;
            this._copyName.dispose(param1);
            this._copyName = null;
            this._limitNum.dispose(param1);
            this._limitNum = null;
            this._totalNum.dispose(param1);
            this._totalNum = null;
            this._bigMap.dispose(param1);
            this._bigMap = null;
            this._copyTitle.dispose(param1);
            this._copyTitle = null;
            if (this._currentPanel)
            {
                this._currentPanel.dispose(param1);
                this._currentPanel = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyTxt_1, 423, 207, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyTxt_2, 608, 205, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyTxt_3, 668, 207, this));
            this.addChild(this._limitNum);
            this.addChild(this._totalNum);
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updateCopyList();
            this.handleCellRendererChange();
            return;
        }// end function

        private function showMeetCarrarOnly(event:Event) : void
        {
            var _loc_2:* = this._tcopy.rewardShow.split("#");
            this._rewardList.dataProvider = this.getRewardDataProvider(_loc_2);
            return;
        }// end function

        public function changeCopyGroupInfoByIndex(param1:int) : void
        {
            var _loc_2:GroupCopyBaseListPanel = null;
            if (!(this._currentPanel is this._dicIndexClass[param1]))
            {
                if (this._currentPanel)
                {
                    this._currentPanel.dispose();
                    this._currentPanel = null;
                }
                _loc_2 = UICompomentPool.getUICompoment(this._dicIndexClass[param1]);
                this.addChild(_loc_2);
                this._currentPanel = _loc_2;
                this._currentPanel.x = 400;
                this._currentPanel.y = 217;
            }
            this._currentPanel.tcopy = this._tcopy;
            if (this._currentPanel is GroupCopyListPanel)
            {
            }
            else if (this._currentPanel is GroupCopyMateInfoPanel)
            {
                (this._currentPanel as GroupCopyMateInfoPanel).updateGroupMateList();
            }
            return;
        }// end function

        private function handleCellRendererChange(event:Event = null) : void
        {
            var _loc_2:* = Cache.instance.role.entityInfo.level;
            if ((this._copyList.selectedItem.tCopy as TCopy).enterMinLevel > _loc_2 && _loc_2 <= (this._copyList.selectedItem.tCopy as TCopy).enterMaxLevel)
            {
                return MsgManager.showRollTipsMsg(Language.getStringByParam(70885, (this._copyList.selectedItem.tCopy as TCopy).enterMinLevel));
            }
            this._tcopy = this._copyList.selectedItem.tCopy;
            var _loc_3:* = this._tcopy.rewardShow.split("#");
            this._rewardList.dataProvider = this.getRewardDataProvider(_loc_3);
            this._rewardList.x = 16 + (412 - 50 * this._rewardList.dataProvider.length) * 0.5;
            this._copyName.copyUrl = "groupCopyReward_" + this._tcopy.icon + ".png";
            this._totalNum.text = this._tcopy.dayNum.toString();
            this._bigMap.imgUrl = "groupCopyBigMap_" + this._tcopy.icon + ".jpg";
            this._copyTitle.imgUrl = "groupCopyName_" + this._tcopy.icon + ".png";
            if (Cache.instance.group.isInCopyGroup && this._tcopy.code == Cache.instance.group.sgroup.copyCode)
            {
                if (!(this._currentPanel is GroupCopyMateInfoPanel))
                {
                    this.changeCopyGroupInfoByIndex(1);
                }
            }
            else
            {
                this.changeCopyGroupInfoByIndex(0);
            }
            return;
        }// end function

        private function getRewardDataProvider(param1:Array) : DataProvider
        {
            var _loc_3:Object = null;
            var _loc_4:ItemData = null;
            var _loc_6:int = 0;
            var _loc_2:* = new DataProvider();
            var _loc_5:* = param1.length;
            while (_loc_6 < _loc_5)
            {
                
                if (param1[_loc_6])
                {
                    _loc_4 = new ItemData(int(param1[_loc_6]));
                    _loc_3 = {itemData:_loc_4};
                    if (_loc_4.itemInfo && ItemsUtil.isFitCarrer(_loc_4))
                    {
                        _loc_3 = {itemData:_loc_4};
                        _loc_2.addItem(_loc_3);
                    }
                }
                _loc_6++;
            }
            return _loc_2;
        }// end function

        private function getCopyDataProvider() : DataProvider
        {
            var _loc_3:Object = null;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = CopyConfig.instance.getGroupCopyByLevel(Cache.instance.role.roleInfo.level);
            var _loc_4:* = (this._pageSelecter.currentPage - 1) * 4;
            var _loc_5:* = this._pageSelecter.currentPage * 4 > _loc_2.length ? (_loc_2.length) : (this._pageSelecter.currentPage * 4);
            this._pageSelecter.maxPage = Math.ceil(_loc_2.length / 4);
            var _loc_6:* = _loc_4;
            while (_loc_6 < _loc_5)
            {
                
                _loc_3 = {tCopy:_loc_2[_loc_6]};
                _loc_1.addItem(_loc_3);
                _loc_6++;
            }
            return _loc_1;
        }// end function

        public function updateCopyList() : void
        {
            var _loc_1:int = 0;
            var _loc_2:Boolean = false;
            var _loc_3:int = 0;
            var _loc_4:Object = null;
            this._copyList.dataProvider = this.getCopyDataProvider();
            if (Cache.instance.group.isInCopyGroup)
            {
                _loc_1 = this._copyList.dataProvider.length;
                _loc_2 = false;
                while (_loc_3 < _loc_1)
                {
                    
                    _loc_4 = this._copyList.dataProvider.getItemAt(_loc_3);
                    if (_loc_4.tCopy.code == Cache.instance.group.sgroup.copyCode)
                    {
                        this._copyList.selectedIndex = _loc_3;
                        _loc_2 = true;
                        break;
                    }
                    _loc_3++;
                }
                if (_loc_2 == false)
                {
                    this._copyList.selectedIndex = 0;
                }
            }
            else
            {
                this._copyList.selectedIndex = 0;
            }
            this.handleCellRendererChange();
            return;
        }// end function

        public function updateGroupList(param1:SCopyWaitingGroupMsg) : void
        {
            if (this._currentPanel is GroupCopyListPanel)
            {
                (this._currentPanel as GroupCopyListPanel).updateGroupList(param1);
            }
            return;
        }// end function

        public function updateGroupMateList() : void
        {
            this._copyList.dataProvider = this.getCopyDataProvider();
            if (Cache.instance.group.isInCopyGroup)
            {
                if (this._currentPanel is GroupCopyMateInfoPanel)
                {
                    if (this._tcopy.code == Cache.instance.group.sgroup.copyCode)
                    {
                        (this._currentPanel as GroupCopyMateInfoPanel).updateGroupMateList();
                    }
                    else
                    {
                        this.changeCopyGroupInfoByIndex(0);
                    }
                }
                else if (this._currentPanel is GroupCopyListPanel && this._tcopy.code == Cache.instance.group.sgroup.copyCode)
                {
                    this.changeCopyGroupInfoByIndex(1);
                }
            }
            else if (this._currentPanel is GroupCopyMateInfoPanel)
            {
                this.changeCopyGroupInfoByIndex(0);
            }
            return;
        }// end function

        public function updateLimitNum() : void
        {
            this._limitNum.text = Cache.instance.copy.getGroupCopyEnterNum(ECopyType._ECopyTypeTeam).toString();
            return;
        }// end function

    }
}
